const WxParse = require('../../wxParse/wxParse.js')

Page({
    data: {
        markers: [],
        routeList: []
    },
    onLoad() {
        wx.showLoading({
            title: '加载中'
        })

        wx.showShareMenu({
            withShareTicket: true
        })

        wx.request({
            url: 'https://www.kelionline.com/api/miniProgram/mnm/trafficList',
            method: 'GET',
            success: res => {
                if (res.data.code == 0) {
                    wx.hideLoading()

                    const data = res.data.data

                    for (let i = 0; i < data.list.length; i++) {
                        WxParse.wxParse('content[' + i + ']', 'html', data.list[i].content, this)
                    }

                    const location = data.location.split(',')
                    
                    this.setData({
                        markers: [{
                            id: 1,
                            iconPath: '/resources/others.png',
                            latitude: location[1],
                            longitude: location[0],
                            width: 18,
                            height: 36
                        }],
                        routeList: data.list
                    })
                }
            }
        })
    },
    showMap() {
        wx.openLocation({
            latitude: Number(this.data.markers[0].latitude),
            longitude: Number(this.data.markers[0].longitude)
        })
    }
})